#include <stdio.h>


int main(void) {
	int n, i, j, sum;




	scanf("%d", &n);
	int a[n][n];
	for ( i = 0; i < n; i++ )
		for ( j = 0; j < n; j++ )
			scanf("%d", &a[i][j]);

	int r = 0;
	int c = 0;
	for ( i = 0; i < n; i++ ) {
		for ( j = 0; j < n; j++ ) {
			if (a[i][j] < a[r][c])
				r = i;
			c = j;
		}
	}

	int temp = a[0][0];
	a[0][0] = a[r][c];
	a[r][c] = temp;
	r = 0;
	c = 1;
	for (j = 1; j < n; j++) {
		if (a[0][j] < a[r][c]) {
			c = j;
		}
	}
	for ( i = 1; i < n; i++ ) {
		for ( j = 0; j < n; j++ ) {
			if (a[i][j] < a[r][c]) {
				r = i;
				c = j;
			}

		}
	}
	temp = a[n - 1][n - 1];
	a[n - 1][n - 1] = a[r][c];
	a[r][c] = temp;


	for ( i = 0; i < n; i++ ) {
		for ( j = 0; j < n; j++ ) {
			printf("%d", a[i][j]);
			if (j != n - 1) {
				printf(" ");
			}
		}
		printf("\n");
	}



	return 0;
}